Chapter 5 Community composition
5.1 Taxonomy overview
5.1.1 Stacked barplot
# Merge data frames based on sample
# transplants_metadata <- sample_metadata %>%
# mutate(Tube_code = str_remove_all(Tube_code, "_a"))
# transplants_metadata$newID <- paste(transplants_metadata$Tube_code,
# "_",
# transplants_metadata$individual)
merged_data <- genome_counts_filt %>%
mutate_at(vars(-genome), ~ . / sum(.)) %>% #apply TSS normalisation
pivot_longer(-genome, names_to = "sample", values_to = "count") %>% #reduce to minimum number of columns
left_join(., genome_metadata, by = join_by(genome == genome)) %>% #append genome metadata
left_join(., sample_metadata, by = join_by(sample == Tube_code)) %>% #append sample metadata
filter(count > 0) #filter 0 counts
ggplot(merged_data, aes(
x = sample,
y = count,
fill = phylum,
group = phylum
)) + #grouping enables keeping the same sorting of taxonomic units
geom_bar(stat = "identity",
colour = "white",
linewidth = 0.1) + #plot stacked bars with white borders
scale_fill_manual(values = phylum_colors) +
facet_nested(. ~ time_point + type , scales = "free") + #facet per day and treatment
guides(fill = guide_legend(ncol = 1)) +
labs(fill = "Phylum", y = "Relative abundance", x = "Sample") +
theme(
axis.text.x = element_text(
angle = 45,
hjust = 1,
size = 0
),
strip.text.x = element_text(
size = 14,
colour = "black",
face = "bold"
),
strip.background = element_rect(fill ="lightgrey"),
axis.title = element_text(size = 18, face = "bold"),
panel.background = element_blank(),
legend.title = element_text(size = 20, face = "bold"),
legend.text = element_text(size = 16)
)5.1.1.1 Wild samples
merged_data %>%
filter(time_point=="Wild") %>%
ggplot(aes(x=sample,y=count, fill=phylum, group=phylum)) + #grouping enables keeping the same sorting of taxonomic units
geom_bar(stat="identity", colour="white", linewidth=0.1) + #plot stacked bars with white borders
scale_fill_manual(values=phylum_colors) +
facet_nested(. ~ Population, scales="free") + #facet per day and treatment
guides(fill = guide_legend(ncol = 1)) +
labs(fill="Phylum",y = "Relative abundance",x="Sample")+
theme(
axis.text.x = element_text(
angle = 45,
hjust = 1,
size = 0
),
strip.text.x = element_text(
size = 14,
colour = "black",
face = "bold"
),
axis.title = element_text(size = 18, face = "bold"),
panel.background = element_blank(),
strip.background = element_rect(fill ="lightgrey"),
legend.title = element_text(size = 20, face = "bold"),
legend.text = element_text(size = 16)
)5.1.2 Phylum relative abundances
phylum_summary <- genome_counts_filt %>%
mutate_at(vars(-genome),~./sum(.)) %>% #apply TSS normalisation
pivot_longer(-genome, names_to = "sample", values_to = "count") %>%
left_join(sample_metadata, by = join_by(sample == Tube_code)) %>%
left_join(genome_metadata, by = join_by(genome == genome)) %>%
group_by(sample,phylum) %>%
summarise(relabun=sum(count))5.1.2.1 Cold and wet population
phylum_summary %>%
left_join(sample_metadata, by = join_by(sample == Tube_code)) %>%
group_by(phylum, Population) %>%
filter(Population=="Cold_wet" & time_point=="Wild") %>%
summarise(total_mean=mean(relabun*100, na.rm=T),
total_sd=sd(relabun*100, na.rm=T)) %>%
filter(total_mean!=0) %>%
mutate(total=str_c(round(total_mean,2),"±",round(total_sd,2))) %>%
arrange(-total_mean) %>%
dplyr::select(phylum,total) %>%
tt()